<?php
include('includes/basic.php');
$custname=$_POST['cust_name'];
$uname=$_POST['user_name'];

//$status=$_POST['recordstatus'];
$cid=$_POST['custid'];
$cust_desc=addslashes($_POST['cust_desc']);
$mob=$_POST['mob'];
$add=addslashes($_POST['add']);

$usertypeid=$_POST['usertypeid'];
$password=md5($_POST['password']);
$custcontname=$_POST['cust_contname'];


$update=mysql_query("update customer_master set customer='$custname', cust_desc='$cust_desc',user_name='$uname', password='$password' where customer_id=$cid");


if($update)
	{
		$checkdt=mysql_query("select * from customer_contact where customer_id='$usertypeid'");
		if(mysql_num_rows($checkdt)>0)
		{

		$update1=mysql_query("update customer_contact set mobile='$mob', `customer_name`='$custcontname', address='$add' where customer_id='$usertypeid'");

		}
		else
		{

		$update1=mysql_query("insert into customer_contact(`customer_id`,`customer_name`,`mobile`,`address`) values ('$usertypeid','$custcontname','$mob','$add')");

				
		}
	}

if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
			{

				$fileName = $_FILES['uploadedfile']['name'];
				$tmpName = $_FILES['uploadedfile']['tmp_name'];
				$fileSize = $_FILES['uploadedfile']['size'];
				$fileType = $_FILES['uploadedfile']['type'];
				
				$fp      = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);
				
				if(!get_magic_quotes_gpc())
				{
					$fileName = addslashes($fileName);
				}
				$check = mysql_query("select * from customer_logo where customer_id='$usertypeid'");
				if(mysql_num_rows($check)>0)
				{

				$query = "update customer_logo set name='$fileName', size='$fileSize', type='$fileType', content='$content', uploaded_on=sysdate() where customer_id='$usertypeid'";

				}
				else
				{
				$query = "INSERT INTO customer_logo (customer_id,name, size, type, content, uploaded_on) VALUES ('$usertypeid','$fileName', '$fileSize', '$fileType', '$content', sysdate())";
				}

				mysql_query($query) or die('Error, query failed'); 

				
			}
if($update1)
	{
		//echo $custname;
		header("location:view-customers.php");
	}


?>